/*
 * 公用弹窗类
 * @author: huangzong
 */
const C = require('../common/common')

class Popup {
    constructor() {}

    /*
     * 选择开卡产品类型
     */
    async openCardTypePopup(filter, data) {
        return await C.openBrowserWindow('/selectOpenCardRowType', { filter: filter, data: data }, {
            width: 500,
            height: 330,
            transparent: true,
            frame: false,
            // openDevTools: true,
            useSpa: true,
            spaModel: 'shop'
        })
    }

    // 选择产品、卡项、项目
    async typeGoodsPopup(filter, data) {
        let url
        switch (filter.rowtype) {
            case 1:
                url = '/goodsPopup'
                break
            case 2:
                url = '/subjectPopup'
                break
            case 3:
                url = '/cardsPopup'
                break
        }
        return await C.openBrowserWindow(url, { filter: filter, data: data }, {
            width: 900,
            height: 600,
            transparent: true,
            frame: false,
            // openDevTools: true,
            useSpa: true,
            spaModel: 'shop'
        })
    }
    // 选择账户
    async accountPopup(filter, data) {
        return await C.openBrowserWindow('/accountPopup', { filter: filter, data: data }, {
            transparent: true,
            frame: false,
            // openDevTools: true,
            useSpa: true,
            spaModel: 'shop'
        })
    }

    async userPopup(filter, data) {
        return await C.openBrowserWindow('/userPopup', { filter: filter, data: data }, {
            transparent: true,
            frame: false,
            // openDevTools: true,
            useSpa: true,
            spaModel: 'shop'
        })
    }

    async openOrderGoodsPopup(filter, data) {
        let url
        switch (filter.rowtype) {
            case 1:
            case 2:
                return await this.typeGoodsPopup(filter, data)
            case 3:
                url = '/guestSubjectPopup'
                break
            case 4:
                url = '/guestStorePopup'
                break
        }
        return await C.openBrowserWindow(url, { filter: filter, data: data }, { width: 900, height: 600, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
    }


    /*
     * 普通弹框
     */


    // 开卡页面
    async openCardPopup(filter) {
        return await C.openBrowserWindow('/addOpenCard', filter, { width: 1600, height: 900, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
    }

    // 开单页面
    async openOrderPopup(filter) {
        return await C.openBrowserWindow('/openOrder', filter, { width: 1600, height: 900, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
    }

    // 充值
    async openRechargePopup(filter) {
        return await C.openBrowserWindow('/rechargeOrder', filter, { width: 1600, height: 900, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
    }

    // 出入库信息
    async openStockPopup(filter) {
        return await C.openBrowserWindow('/stockOrderInfo', filter, { width: 1200, height: 880, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
    }

    // 领料
    async openPickPopup(filter) {
        return await C.openBrowserWindow('/pickOrderInfo', filter, { width: 1600, height: 900, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
    }

    // 退卡、退款
    async openBackPopup(filter) {
        return await C.openBrowserWindow('/backCardInfo', filter, { width: 1600, height: 900, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
    }


    // 通用订单详细查看页面
    async showOrderPopup(filter) {
        // 根据ordertype判断
        switch (filter.ordertype) {
            case 1:
            case 'KKD':
                return await this.openCardPopup({ id: filter.id, status: filter.status })
            case 2:
            case 'LSD':
                return await this.openOrderPopup({ id: filter.id, status: filter.status })
            case 3:
            case 'CZD':
                return await this.openRechargePopup({ orderid: filter.id })
            case 'CKD':
            case 'RKD':
            case 6:
            case 7:
                return await this.openStockPopup({ id: filter.id })
            case 'LLD':
            case 'TLD':
            case 8:
            case 9:
                return await this.openPickPopup({ id: filter.id })
            case 'TKD':
            case 'TQD':
            case 10:
            case 11:
                return await this.openBackPopup({ id: filter.id })
        }
    }
}

module.exports = new Popup()